import tvm
from tvm import te

def add_custom(x, y, z, length):
    """
    自定义加法算子定义
    :param x: 输入tensor1
    :param y: 输入tensor2
    :param z: 输出tensor
    :param length: 数据长度
    """
    ib = tvm.tir.ir_builder.create()
    
    # 数据指针声明
    x_ptr = ib.buffer_ptr(x)
    y_ptr = ib.buffer_ptr(y)
    z_ptr = ib.buffer_ptr(z)
    
    # 核函数网格划分
    with ib.for_range(0, length, name="i", kind="parallel") as i:
        z_ptr[i] = x_ptr[i] + y_ptr[i]
    
    return ib.get()